package main

import (
	"fmt"
	"net/http"
	"text/template"
)

func Hello(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello World")
}

type Person struct {
	Name string
	Age int
}

func Index(w http.ResponseWriter, r *http.Request) {
	p := Person{"Cara", 18}
	t, err := template.ParseFiles("index.html")
	if err != nil {
		fmt.Println("加载模板ERROR:", err)
		return
	}
	t.Execute(w, p)
}

func main() {
	http.HandleFunc("/", Hello)
	http.HandleFunc("/index", Index)
	err := http.ListenAndServe("0.0.0.0:8000", nil)
	if err != nil {
		fmt.Println("http Listen failed")
	}
}